package com.weibo.view.activity;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import swing2swt.layout.BorderLayout;
import weibo4j.model.User;

import com.weibo.action.UserAction;
import com.weibo.util.ImageUtil;
import com.weibo.util.MathUtil;
import com.weibo.util.ProvinceUtil;
import com.weibo.view.composite.IndexComposite;

public class WeiboActivity {

	public static final int width  = 700;
	public static final int height = 500;
	
	protected Shell shell;
	protected Button collect;
	private Button priletter;
	private Button comments;
	private Button atme;
	private Button index;
	private Label procity;
	private Label username;
	private Label headicon;
	private Display display;
	private Label weibonums;
	private Label fansnums;
	private Label guanzhunums;

	public static void main(String[] args) {
		new WeiboActivity().open();
	}
	/**
	 * Open the window.
	 */
	public void open() {
		display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		loadData();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 * @wbp.parser.entryPoint
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(width, height);
		shell.setLocation(new Point((MathUtil.getscreenw()-width)/2, (MathUtil.getscreenh()-height)/2));
		shell.setText("sina微博");
		shell.setLayout(new BorderLayout(0, 0));
		
		Label lblNewLabel_1 = new Label(shell, SWT.NONE);
		lblNewLabel_1.setLayoutData(BorderLayout.SOUTH);
		lblNewLabel_1.setText("status");
		
		IndexComposite center = new IndexComposite(shell, SWT.NONE);
		center.paint();
		
		Composite west = new Composite(shell, SWT.NONE);
		west.setLayoutData(BorderLayout.EAST);
		
		headicon = new Label(west, SWT.IMAGE_PNG);
		headicon.setBounds(0, 0, 59, 48);
		
		username = new Label(west, SWT.NONE);
		username.setBounds(65, 0, 105, 17);
		username.setText("null");
		
		procity = new Label(west, SWT.NONE);
		procity.setBounds(67, 30, 103, 17);
		procity.setText("null");
		
		index = new Button(west, SWT.NONE);
		index.setBounds(0, 93, 80, 27);
		index.setText("我的首页");
		
		atme = new Button(west, SWT.NONE);
		atme.setBounds(0, 126, 80, 27);
		atme.setText("@提到我的");
		
		comments = new Button(west, SWT.NONE);
		comments.setBounds(0, 159, 80, 27);
		comments.setText("我的评论");
		
		priletter = new Button(west, SWT.NONE);
		priletter.setBounds(0, 192, 80, 27);
		priletter.setText("我的私信");
		
		collect = new Button(west, SWT.NONE);
		collect.setBounds(0, 225, 80, 27);
		collect.setText("我的收藏");
		
		weibonums = new Label(west, SWT.NONE);
		weibonums.setBounds(0, 63, 53, 17);
		weibonums.setText("微博数:");
		
		fansnums = new Label(west, SWT.NONE);
		fansnums.setBounds(55, 63, 53, 17);
		fansnums.setText("粉丝数:");
		
		guanzhunums = new Label(west, SWT.NONE);
		guanzhunums.setBounds(110, 63,53, 17);
		guanzhunums.setText("关注:");
	}
	
	public void loadData(){
		UserAction userAction = new UserAction();
		User user = userAction.getUserInfo();
		shell.setText(user.getName()+"的新浪微博");
		headicon.setImage(ImageUtil.getURLImage(shell.getDisplay(), user.getProfileImageUrl()));
		username.setText(user.getName());
		procity.setText(ProvinceUtil.getProvince(user.getProvince(),user.getCity()));
		weibonums.setText(weibonums.getText()+user.getStatusesCount());
		fansnums.setText(fansnums.getText()+user.getBiFollowersCount());
		guanzhunums.setText(guanzhunums.getText()+user.getFriendsCount());
	}
}
